package com.crcc.common.sequence;


import com.crcc.common.util.SpringContextUtil;

/**
 * 全局ID生成机制
 *
 * @author dongy
 */
public class SequenceBean {

	private volatile static Sequence sequence ;

	private SequenceBean() {}

	public static long getSequence(){
		if(sequence == null){
			synchronized (SequenceBean.class){
				if(sequence == null){
					Long workerId = Long.valueOf((String) SpringContextUtil.getProperty("5"));
					Long datacenterId = Long.valueOf((String)SpringContextUtil.getProperty("1"));
					sequence = new Sequence(workerId, datacenterId);
				}
			}
		}
		return sequence.nextId();
	}
}
